package com.todod.base.module.base.dal.mysql.rtmaintain.rtmaintainchild;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.todod.base.framework.common.pojo.PageResult;
import com.todod.base.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.todod.base.framework.mybatis.core.mapper.BaseMapperX;
import com.todod.base.module.base.controller.admin.rtmaintain.rtmaintainchild.vo.RtMaintainChildPageReqVO;
import com.todod.base.module.base.dal.dataobject.rtmaintain.rtmaintainchild.RtMaintainChildDO;
import jdk.dynalink.linker.LinkerServices;
import org.apache.ibatis.annotations.Mapper;

import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 实时数据维护子表 Mapper
 *
 * @author 超管儿
 */
@Mapper
public interface RtMaintainChildMapper extends BaseMapperX<RtMaintainChildDO> {

    default PageResult<RtMaintainChildDO> selectPage(RtMaintainChildPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RtMaintainChildDO>()
                .betweenIfPresent(RtMaintainChildDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RtMaintainChildDO::getId));
    }

    /**
     * 取仪器的最新一条数据---根据仪器编号获取其最新的传输过来的明细数据（子表单表查询，一条）
     */
    default RtMaintainChildDO getRtMaintainChildByCode(String deviceCode) {
        return selectOne(new LambdaQueryWrapperX<RtMaintainChildDO>()
                .eqIfPresent(RtMaintainChildDO::getDeviceCode,deviceCode)
                .orderByDesc(RtMaintainChildDO::getCreateTime)
                .last("limit 1"));
    }
    /**
     * 取仪器的一天内的时间范围内数据---根据仪器代码和时间段参数获取其最新的传输过来的列表数据（子表单表查询，列表，时间正序）
     */
    default List<RtMaintainChildDO> getRtMaintainChildByCreateTimeList(RtMaintainChildPageReqVO reqVO){
        return selectList(new LambdaQueryWrapperX<RtMaintainChildDO>()
                .betweenIfPresent(RtMaintainChildDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(RtMaintainChildDO::getCreateTime));
    }


    /**
     * 根据父级ID获取对应子表信息
     */
    default RtMaintainChildDO getRtMaintainChildByParentId(RtMaintainChildPageReqVO reqVO) {
        return selectOne(new LambdaQueryWrapperX<RtMaintainChildDO>()
                .eqIfPresent(RtMaintainChildDO::getParentId,reqVO.getParentId())
        );
    }

    //------------------------------------------------------------------------------------------------------------------------------
    /**
     * 按照要求取一条最新数据（通用）
     */
    default RtMaintainChildDO getRtMaintainChildNewOne(RtMaintainChildPageReqVO reqVO) {
        return selectOne(new LambdaQueryWrapperX<RtMaintainChildDO>()
                .eqIfPresent(RtMaintainChildDO::getP4,reqVO.getP4())
                .betweenIfPresent(RtMaintainChildDO::getCreateTime, reqVO.getCreateTime())//实时秒数据:根据时间要求查询最新实时秒数据
                .betweenIfPresent(RtMaintainChildDO::getP5, reqVO.getP5())//实测整米数据:根据井深范围要求查询最新实测整米数据
                .betweenIfPresent(RtMaintainChildDO::getP6, reqVO.getP6())//迟到整米数据:根据迟到井深范围要求查询最新实测整米数据
                .orderByDesc(RtMaintainChildDO::getCreateTime)
                .last("limit 1"));
    }
    /**
     * 按照要求查询列表（通用）
     */
    default List<RtMaintainChildDO> getRtMaintainChildList(RtMaintainChildPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<RtMaintainChildDO>()
                .eqIfPresent(RtMaintainChildDO::getP4,reqVO.getP4())
                .betweenIfPresent(RtMaintainChildDO::getCreateTime, reqVO.getCreateTime())//实时秒数据:根据时间要求查询实时秒数据(列表)
                .betweenIfPresent(RtMaintainChildDO::getP5, reqVO.getP5())//实测整米数据:根据井深范围要求查询实测整米数据(列表)
                .betweenIfPresent(RtMaintainChildDO::getP6, reqVO.getP6())//迟到整米数据:根据迟到井深范围要求查询实测整米数据(列表)
                .orderByAsc(RtMaintainChildDO::getCreateTime)
                /*.last("limit 100")*/
        );
    }



    //------------------------------------------------------------------------------------------------------------------------------







}